package com.aqie.arithmetic.string;

public class MyString {

    // 判断字符串是否是回文
    public static boolean isPalindrome(String s){
        int N = s.length();
        for (int i = 0; i < N / 2; i ++){
            if (s.charAt(i) != s.charAt(N-i-1)) return false;
        }
        return true;
    }

    // 获取文件名及扩展名
    public static void getFileNameAndExtension(String fileName){
        int dot = fileName.indexOf(".");
        System.out.println("base: " + fileName.substring(0, dot));
        System.out.println("extension: " + fileName.substring(dot + 1, fileName.length()));
    }

    // 检查字符串数组中元素是否按照字母表顺序排序
    public static boolean isSorted(String[] a){
        for (int i = 1; i < a.length; i++){
            if (a[i - 1].compareTo(a[i]) > 0) return false;
        }
        return true;
    }

    public static void main(String[] args) {
        String fileName  = "aqie.a.txt";
        getFileNameAndExtension(fileName);
        String[] a = {"a", "b", "c", "w", "p"};
        System.out.println(isSorted(a));
    }
}
